package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.Workers;
import com.fantastic.service.zjs.WorkersService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: rxx
 * @since: 2024/5/27 11:44
 * @description:
 */
@RestController
@RequestMapping("/workers")
public class WorkersControllerAdmin {
    @Resource
    private WorkersService workersService;

    /**
     * 查询
     * 无条件时是查询全部的分页查询
     * 有条件时是查询条件的分页查询
     *
     * @param workers 员工信息对象
     * @return
     */
    @GetMapping("/listWorkers")
    public ResultData listWorkers(Workers workers,
                                  @RequestParam(name="page",
                                          defaultValue = "1") int pageNum,
                                  @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        //设置分页逻辑
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Workers> pageInfo = new PageInfo<>(workersService.listWorkers(workers));
        return new ResultData(RespStatusInfo.OK, pageInfo);
    }

    /**
     * 查询单个员工的信息
     *
     * @param workerId 员工id
     * @return
     */
    @GetMapping("/getWorkers")
    public ResultData getWorkers(Integer workerId) {
        return new ResultData(RespStatusInfo.OK, workersService.getWorkers(workerId));
    }

    /**
     * 添加员工信息
     *
     * @param workers
     * @return
     */
    @PostMapping("/insertWorkers")
    public ResultData insertWorkers(@RequestBody Workers workers) {
        return new ResultData(RespStatusInfo.OK, workersService.insertWorkers(workers));
    }

    /**
     * 修改员工信息
     *
     * @param workers
     * @return
     */
    @PostMapping("/updateWorkers")
    public ResultData updateWorkers(@RequestBody Workers workers) {
        return new ResultData(RespStatusInfo.OK, workersService.insertWorkers(workers));
    }

    /**
     * 删除员工信息
     *
     * @param
     * @return
     */
    @PostMapping("/deleteWorkers")
    public ResultData deleteWorkers(Integer workerId) {
        return new ResultData(RespStatusInfo.OK, workersService.deleteWorkers(workerId));
    }


}
